/*
 * Package il.ac.biu.cs.grossmm.cpp
 * File CppServiceConsumer.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.api.cpp;

import il.ac.biu.cs.grossmm.api.keys.Key;
import il.ac.biu.cs.grossmm.api.presence.Entity;

/**
 * An interface to be implemented by a CPP service consumer, which is a user
 * object. CPP service consumers are usually protocol adapters which translate
 * between abstract CPP protocol and concrete presence protocol.
 * <p>
 * CPP service consumer sends subscribe requests to CPP service provider (which
 * implements <tt>CppServiceProvider</tt> interface) by invoking
 * <tt>CppServiceProvider.subscribe</tt> method. Notifications for active
 * subscriptions are sent to the CPP service consumer by callng a
 * <tt>notify</tt> method of this interface.
 * 
 * <pre>
 *    +-----------+                    +-----------+
 *    |           |                    |           |
 *    |    CPP    |                    |    CPP    |
 *    |  service  | &lt;----- notify ---- |  service  |
 *    | consumer  |                    |  provider |
 *    |           |                    |           |   
 *    +-----------+                    +-----------+
 * </pre>
 * 
 * <p>
 * CPP service consumer is linked to CPP sevrice provider when obtaining the
 * reference to a implementation of <tt>CppServiceManager</tt> object by
 * invoking <tt>CppServiceManager.getServiceProvider</tt> method
 * 
 */
public interface CppServiceConsumer<T> {
	/**
	 * Sends a notification based on a notify operaton defined by RFC 3859.
	 * <p>
	 * The notify operation has the following attributes: watcher, target,
	 * state, state, subscriptID and contents. The values of 'watcher', 'target'
	 * and 'subscriptID' are identical to those given in the subscribe operation
	 * that triggered this notify operation.
	 * <p>
	 * The 'state' contains the status of the subscription and the remaining
	 * duration of the subscription. The 'contents' is a java object which
	 * repsesents the contents of the notification. The java-type of this object
	 * corresponds to the generic parameter <tt>T</tt>.
	 * <p>
	 * If status of subscription is 'failure' (represented by <tt>false</tt>
	 * in Java), then values of the remaining duration and notification contents
	 * should be ignored.
	 * 
	 * @param watcher
	 *            the watcher identical the value of the watcher parameter given
	 *            in the subscribe operation that triggered this notify
	 *            operation.
	 * 
	 * @param target
	 *            the target identical the value of the target parameter given
	 *            in the subscribe operation that triggered this notify
	 *            operation.
	 * @param state
	 *            describes the state of presence: the status and the remaining
	 *            subscription duration
	 * @param subscriptID
	 *            the subscriptID identical the value of the subscriptID
	 *            parameter given in the subscribe operation
	 * @param contents
	 *            is a java object which repsesents the contents of the
	 *            notification. The java-type of this object corresponds to the
	 *            generic parameter <tt>T</tt>.
	 */
	void notify(Entity watcher, Key target, State state, String subscriptID,
		T contents);
}
